<template>
  <view>
    <view class="user-info" :style="'background-image: url('+userBg+');'">
      <view class="u-flex u-m-b-16">
        <image style="width: 100rpx;height: 100rpx;margin-right: 26rpx;" :src="form.avatar" mode="aspectFill" />
        <view>
          <view class="u-font-28 u-m-b-8">{{ form.nickName }}</view>
          <view class="u-font-24">{{ form.phonenumber }}</view>
        </view>
      </view>
      <view class="u-font-28 u-m-b-12" id="companyName" @click="copy('companyName')">{{ form.companyName }}</view>
      <view class="u-font-28 u-m-b-12" id="slogan" @click="copy('slogan')" style="font-weight: 500;">{{ form.slogan }}</view>
      <view class="u-font-24" id="companyAddress" @click="copy('companyAddress')" style="color: #818181;">地址：{{ form.companyAddress }}</view>
    </view>
    <view class="ql-editor" id="introduction" @click="copy('introduction')" v-html="form.introduction"></view>
    <view class="share-btn" @click="share(true)">
      <image src="../../../static/my/share1.png" />
    </view>
  </view>
</template>

<script>
import "@vueup/vue-quill/dist/vue-quill.snow.css"
import userBg from '../../../static/my/materialCenterUser.png'
import { getCompanyInfo } from '@/api/index'
import { wxShare } from '@/common/util'

export default {
  data() {
    return {
      userBg,
      form: {},
    };
  },
  mounted() {
    getCompanyInfo({ deptId: uni.getStorageSync('userInfo').deptId, }).then(res => {
      this.form = res.data || {}
    })
  },
  methods: {
    copy(id) {
     const richTextElement = document.getElementById(id)
      const pureText = richTextElement.textContent || richTextElement.innerText;
      navigator.clipboard.writeText(pureText).then(() => {
        uni.showToast({
          title: '复制成功',
          icon: 'none'
        })
      }).catch(err => {
        uni.showToast({
          title: '复制失败',
          icon: 'none'
        })
      });
    },
    share(f) {
      const userInfo = uni.getStorageSync('userInfo')
      const shareInfo = {
        title: this.form.companyName,
        link: this.httpUrl + `/pages/my/enterpriseInfo?shareFlag=1`,
        desc: this.form.slogan,
      }
      shareInfo.link = shareInfo.link + '&invitationCode=' + userInfo.invitationCode
      if(userInfo.wechatQrCode) {
        shareInfo.link = shareInfo.link + '&wechatQrCode=' + userInfo.wechatQrCode
      }
      wxShare(shareInfo, f)
    }
  },
};
</script>

<style lang="scss" scoped>
.user-info {
  width: 702rpx;
  height: 306rpx;
  background-color: #fff;
  background-repeat: no-repeat;
  background-size: 702rpx 306rpx;
  margin: 0 auto 12rpx;
  border-radius: 12rpx;
  padding: 24rpx;
}
.share-btn {
  width: 80rpx;
  height: 80rpx;
  position: fixed;
  right: 12rpx;
  bottom: 42rpx;
  image {
    width: 80rpx;
    height: 80rpx;
  }
}
</style>
